package com.cqupt.controller;

import com.cqupt.model.pojo.ScoreRecord;
import com.cqupt.model.pojo.SignRecord;
import com.cqupt.model.vo.Result;
import com.cqupt.model.vo.ResultCodeEnum;
import com.cqupt.model.vo.StudyDataVO;
import com.cqupt.service.ArticleRecordService;
import com.cqupt.service.ScoreRecordService;
import com.cqupt.service.SignRecordService;
import com.cqupt.service.TimeRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/record")
@Tag(name = "学习记录模块")
public class RecordController {

    @Resource
    private ScoreRecordService scoreRecordService;

    @Resource
    private SignRecordService signRecordService;

    @Resource
    private TimeRecordService timeRecordService;

    @Resource
    private ArticleRecordService articleRecordService;


    @GetMapping("/scoreRecord")
    @Operation(summary = "口语分数记录")
    public Result scoreRecord() {
        ScoreRecord scoreRecord = scoreRecordService.scoreRecord();
        return Result.build(scoreRecord, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/suggest")
    @Operation(summary = "根据口语分数获取学习建议")
    public Result suggest(@RequestBody ScoreRecord scoreRecord) {
        String res = scoreRecordService.suggest(scoreRecord);
        return Result.build(res, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/signRecord")
    @Operation(summary = "获取签到记录")
    public Result signRecord() {
        List<String> signRecords = signRecordService.signRecord();
        return Result.build(signRecords, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/sign")
    @Operation(summary = "用户签到")
    public Result sign(@RequestParam String date) {
        signRecordService.sign(date);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/updateTime")
    @Operation(summary = "更新学习时长")
    public Result updateTime(@RequestParam String date, @RequestParam int minutes) {
        timeRecordService.updateTime(date, minutes);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/data")
    @Operation(summary = "获取学习数据")
    public Result studyData() {
        StudyDataVO studyDataVO = articleRecordService.studyData();
        return Result.build(studyDataVO, ResultCodeEnum.SUCCESS);
    }

}
